package vip.xiaonuo.smzq.modular.psba.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.models.auth.In;
import org.apache.poi.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import oshi.driver.mac.net.NetStat;
import vip.xiaonuo.common.exception.CommonException;
import vip.xiaonuo.smzq.modular.deom.TypeProcessing;
import vip.xiaonuo.smzq.modular.dictionary.entity.*;
import vip.xiaonuo.smzq.modular.dictionary.mapper.*;
import vip.xiaonuo.smzq.modular.kcl.entity.Zl;
import vip.xiaonuo.smzq.modular.kcl.entity.vo.ClspVo;
import vip.xiaonuo.smzq.modular.kcl.entity.vo.Kszlzb;
import vip.xiaonuo.smzq.modular.kcl.entity.vo.ReservesEdit;
import vip.xiaonuo.smzq.modular.psba.entity.*;
import vip.xiaonuo.smzq.modular.psba.entity.param.PsbaApprove;
import vip.xiaonuo.smzq.modular.psba.entity.param.PsbaXqParam;
import vip.xiaonuo.smzq.modular.psba.entity.vo.*;
import vip.xiaonuo.smzq.modular.psba.mapper.*;
import vip.xiaonuo.smzq.modular.psba.service.*;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import vip.xiaonuo.common.page.CommonPageRequest;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 评审备案-非压覆基本情况 服务实现类
 *
 * @author Kevin
 * @since 2024-05-15
 */
@Service
public class PsbaGtJbqkServiceImpl extends ServiceImpl<PsbaGtJbqkMapper, PsbaGtJbqk> implements IPsbaGtJbqkService {

    @Resource
    private PsbaGtJbqkMapper psbaGtJbqkMapper;
    @Resource
    private Cb08XzqhMapper cb08XzqhMapper;
    @Resource
    private IPsbaGtBgService iPsbaGtBgService;//报告
    @Resource
    private IPsbaGtDztjService iPsbaGtDztjService;//地质条件
    @Resource
    private IPsbaGtZbService iPsbaGtZbService;//坐标
    @Resource
    private IPsbaGtZyclService iPsbaGtZyclService;//评审备案矿产资源储量
    @Resource
    private IPsbaGtKjzyclService iPsbaGtKjzyclService;//评审备案—重叠范围内资源储量
    @Resource
    private IPsbaGtZlService iPsbaGtZlService;//评审备案-质量
    @Autowired
    private Cb06KcMapper cb06KcMapper;//矿产
    @Resource
    private IPsbaSqjlCzrzService iPsbaSqjlCzrzService;
    @Autowired
    private PsbaSqjlMapper psbaSqjlMapper;
    @Autowired
    private PsbaGtZyclMapper psbaGtZyclMapper;
    @Autowired
    private PsbaGtZlMapper zlMapper;
    @Autowired
    private PsbaGtBgMapper bgMapper;
    @Autowired
    private PsbaGtDztjMapper dztjMapper;
    @Resource
    private Cb03KspjMapper cb03KspjMapper;//矿石品级
    @Resource
    private Cb02KslxMapper cb02KslxMapper;//矿石类型
    @Resource
    private PsbaGtZlMapper psbaGtZlMapper;//矿石质量
    @Resource
    private Cb13ZycllxMapper cb13ZycllxMapper;

    @Override
    public Page<PsbaGtJbqk> page(long current, long size, String nd, String xzqhdm) {
        Page<PsbaGtJbqk> page = new Page<>(current, size);
        QueryWrapper<PsbaGtJbqk> queryWrapper = new QueryWrapper<>();
        if (xzqhdm != null && !xzqhdm.equals("")) {
            xzqhdm = xzqhdm.replaceAll("0+$", "");
            queryWrapper.like("xzqdm", xzqhdm);
        }
        if (nd != null && !nd.equals("")) {
            queryWrapper.like("yxqz", nd);
        }
        queryWrapper.orderByAsc("psbabh");
        page = psbaGtJbqkMapper.selectPage(page, queryWrapper);

        return page;
    }

    @Override
    public PsbaXqVo getPsbaXqVo(String psbabh) {
        PsbaXqVo psbaXqVo = new PsbaXqVo();
        List<PsbaGtJbqk> psbaGtJbqkList = psbaGtJbqkMapper.selectList(new QueryWrapper<PsbaGtJbqk>().eq("psbabh", psbabh));
        //非压覆基本详情--基本详情
        try {
            if (psbaGtJbqkList != null && psbaGtJbqkList.size() > 0) {
                PsbaGtJbqk psbaGtJbqk = psbaGtJbqkList.get(0);
                PsbaGtJbqkVo psbaGtJbqkVo = new PsbaGtJbqkVo();
                BeanUtil.copyProperties(psbaGtJbqk, psbaGtJbqkVo);

                if (psbaGtJbqk.getXzqdm() != null) {
                    //县
                    QueryWrapper<Cb08Xzqh> xianWrapper = new QueryWrapper<>();
                    xianWrapper.eq("dm", Integer.parseInt(psbaGtJbqk.getXzqdm()));
                    Cb08Xzqh xian = cb08XzqhMapper.selectOne(xianWrapper);

                    //市
                    QueryWrapper<Cb08Xzqh> shiWrapper = new QueryWrapper<>();
                    shiWrapper.eq("dm", xian.getFdm());
                    Cb08Xzqh shi = cb08XzqhMapper.selectOne(shiWrapper);
                    //省
                    QueryWrapper<Cb08Xzqh> shengWrapper = new QueryWrapper<>();
                    shengWrapper.eq("dm", shi.getFdm());
                    Cb08Xzqh sheng = cb08XzqhMapper.selectOne(shengWrapper);
                    String xzqhmc = sheng.getMc() + shi.getMc() + xian.getMc();
                    psbaGtJbqkVo.setXzqhMc(xzqhmc);
                }
                psbaXqVo.setPsbaGtJbqk(psbaGtJbqkVo);
            }
        } catch (Exception e) {

        }

        //非压覆基本详情--报告
        PsbaGtBg psbaGtBg = iPsbaGtBgService.getPsbaGtBg(psbabh);
        if (psbaGtBg != null) {
            psbaXqVo.setPsbaGtBg(psbaGtBg);
        }
        //非压覆基本详情--地质条件
        PsbaGtDztj psbaGtDztj = iPsbaGtDztjService.getPsbaGtDztj(psbabh);
        if (psbaGtDztj != null) {
            psbaXqVo.setPsbaGtDztj(psbaGtDztj);
        }

        //资源储量计算范围
        PsbaGtZbVo psbaGtZb = iPsbaGtZbService.getPsbaGtZbVo(psbabh);
        if (psbaGtZb != null) {
            psbaXqVo.setPsbaGtZb(psbaGtZb);
        }

        //评审备案矿产资源储量
        List<PsbakczyclVo> psbakczyclVoList = iPsbaGtZyclService.getPsbakczyclVoList(psbabh);
        if (psbakczyclVoList != null && psbakczyclVoList.size() > 0) {
            psbaXqVo.setPsbakczyclVoList(psbakczyclVoList);
        }
        //评审备案—重叠范围内资源储量
        List<Cdfwnzycl> cdfwnzyclList = iPsbaGtKjzyclService.getCdfwnzyclList(psbabh);
        if (cdfwnzyclList != null && cdfwnzyclList.size() > 0) {
            psbaXqVo.setCdfwnzyclList(cdfwnzyclList);
        }

        return psbaXqVo;
    }

    /**
     * 添加评审备案-非压覆详情
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void addDetail(PsbaXqParam param) {

        //非压覆基本情况
        QueryWrapper<PsbaGtJbqk> jbqkQueryWrapper = new QueryWrapper<>();
        jbqkQueryWrapper.eq("psbabh", param.getPsbaGtJbqk().getPsbabh());
        psbaGtJbqkMapper.delete(jbqkQueryWrapper);

        this.save(param.getPsbaGtJbqk());

        //报告
        QueryWrapper<PsbaGtBg> bgQueryWrapper = new QueryWrapper<>();
        bgQueryWrapper.eq("psbabh", param.getPsbaGtJbqk().getPsbabh());
        bgMapper.delete(bgQueryWrapper);
        param.getPsbaGtBg().setPsbabh(param.getPsbaGtJbqk().getPsbabh());
        iPsbaGtBgService.save(param.getPsbaGtBg());

        //地质条件
        QueryWrapper<PsbaGtDztj> dztjQueryWrapper = new QueryWrapper<>();
        dztjQueryWrapper.eq("psbabh", param.getPsbaGtJbqk().getPsbabh());
        dztjMapper.delete(dztjQueryWrapper);

        param.getPsbaGtDztj().setPsbabh(param.getPsbaGtJbqk().getPsbabh());
        iPsbaGtDztjService.save(param.getPsbaGtDztj());

        PsbaGtZbVo psbaGtZbVo = new PsbaGtZbVo();
        BeanUtil.copyProperties(param.getPsbaGtZb(), psbaGtZbVo);
        psbaGtZbVo.setPsbabh(param.getPsbaGtJbqk().getPsbabh());
        //资源储量计算范围
        iPsbaGtZbService.addPsbaGtZb(psbaGtZbVo);

        //添加审批提交完成日志
        PsbaApprove psbaApprove = new PsbaApprove();
        psbaApprove.setPsbabh(param.getPsbaGtJbqk().getPsbabh());
        psbaApprove.setType("7");
        iPsbaSqjlCzrzService.addRecord(psbaApprove);

        //更新审核状态已完成
        QueryWrapper<PsbaSqjl> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("psbabh", param.getPsbaGtJbqk().getPsbabh());
        PsbaSqjl psbaSqjl = psbaSqjlMapper.selectOne(queryWrapper);
        if (psbaSqjl != null) {
            psbaSqjl.setShzt("1");
            psbaSqjlMapper.updateById(psbaSqjl);
        }
    }

    /**
     * 添加评审备案-非压覆详情-评审备案矿产资源储量
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void addDetailKc(List<PsbaZycledit> list) {

        if (CollectionUtils.isEmpty(list)) {
            throw new CommonException("数据为空");
        }
        List<PsbaGtZycl> psbaGtZyclList = new ArrayList<>();
        List<PsbaGtZl> zlList = new ArrayList<>();

        //先删除旧数据
        QueryWrapper<PsbaGtZycl> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("psbabh", list.get(0).getPsbabh());
        psbaGtZyclMapper.delete(queryWrapper);

        QueryWrapper<PsbaGtZl> zbQueryWrapper = new QueryWrapper<>();
        zbQueryWrapper.eq("psbabh", list.get(0).getPsbabh());
        zlMapper.delete(zbQueryWrapper);

        for (PsbaZycledit psbaZycledit : list) {
            Integer kcdm=0;
            Integer tjdx=0;
            List<Integer> kzbhList = TypeProcessing.strToList(psbaZycledit.getKcbm());
            if (kzbhList != null && kzbhList.size() == 3) {
                kcdm=kzbhList.get(1);
                tjdx=kzbhList.get(2);
            }



            //保存评审备案-资源储量
            List<PsbaZycl> psbaZyclList = psbaZycledit.getReserveDatas();
            for (int i = 0; i < psbaZyclList.size(); i++) {
                PsbaZycl psbaZycl = psbaZyclList.get(i);
                if (psbaZycl.getNmbyJsl() != null || psbaZycl.getNmbyKsl() != null) {
                    PsbaGtZycl zycl = new PsbaGtZycl();
                    zycl.setPsbabh(psbaZycledit.getPsbabh());
                    zycl.setKcdm(kcdm);
                    zycl.setTjdx(tjdx);
                    zycl.setZycllx(psbaZycl.getLxbm());
                    zycl.setKslx(psbaZycledit.getKslxDm());
                    zycl.setKspj(psbaZycledit.getKspjDm());
                    zycl.setZycllb(19001);
                    zycl.setJsl(psbaZycl.getNmbyJsl());
                    zycl.setKsl(psbaZycl.getNmbyKsl());
                    zycl.setKczh(psbaZycledit.getKczh());
                    psbaGtZyclList.add(zycl);
                }
                if (psbaZycl.getLjcmJsl() != null || psbaZycl.getLjcmKsl() != null) {
                    PsbaGtZycl zycl = new PsbaGtZycl();
                    zycl.setPsbabh(psbaZycledit.getPsbabh());
                    zycl.setKcdm(kcdm);
                    zycl.setZycllx(psbaZycl.getLxbm());
                    zycl.setTjdx(tjdx);
                    zycl.setKslx(psbaZycledit.getKslxDm());
                    zycl.setKspj(psbaZycledit.getKspjDm());
                    zycl.setZycllb(19002);
                    zycl.setJsl(psbaZycl.getLjcmJsl());
                    zycl.setKsl(psbaZycl.getLjcmKsl());
                    zycl.setKczh(psbaZycledit.getKczh());
                    psbaGtZyclList.add(zycl);
                }
                if (psbaZycl.getKczjJsl() != null || psbaZycl.getKczjKsl()!= null) {
                    PsbaGtZycl zycl = new PsbaGtZycl();
                    zycl.setPsbabh(psbaZycledit.getPsbabh());
                    zycl.setKcdm(kcdm);
                    zycl.setZycllx(psbaZycl.getLxbm());
                    zycl.setTjdx(tjdx);
                    zycl.setKslx(psbaZycledit.getKslxDm());
                    zycl.setKspj(psbaZycledit.getKspjDm());
                    zycl.setZycllb(19006);
                    zycl.setJsl(psbaZycl.getKczjJsl());
                    zycl.setKsl(psbaZycl.getKczjKsl());
                    zycl.setKczh(psbaZycledit.getKczh());
                    psbaGtZyclList.add(zycl);
                }
                if (psbaZycl.getCszjJsl() != null || psbaZycl.getCszjKsl() != null) {
                    PsbaGtZycl zycl = new PsbaGtZycl();
                    zycl.setPsbabh(psbaZycledit.getPsbabh());
                    zycl.setKcdm(kcdm);
                    zycl.setZycllx(psbaZycl.getLxbm());
                    zycl.setTjdx(tjdx);
                    zycl.setKslx(psbaZycledit.getKslxDm());
                    zycl.setKspj(psbaZycledit.getKspjDm());
                    zycl.setZycllb(19008);
                    zycl.setJsl(psbaZycl.getCszjJsl());
                    zycl.setKsl(psbaZycl.getCszjKsl());
                    zycl.setKczh(psbaZycledit.getKczh());
                    psbaGtZyclList.add(zycl);
                }
                if (psbaZycl.getSpyflJsl() != null || psbaZycl.getSpyflKsl() != null) {
                    PsbaGtZycl zycl = new PsbaGtZycl();
                    zycl.setPsbabh(psbaZycledit.getPsbabh());
                    zycl.setKcdm(kcdm);
                    zycl.setZycllx(psbaZycl.getLxbm());
                    zycl.setTjdx(tjdx);
                    zycl.setKslx(psbaZycledit.getKslxDm());
                    zycl.setKspj(psbaZycledit.getKspjDm());
                    zycl.setZycllb(19009);
                    zycl.setJsl(psbaZycl.getSpyflJsl());
                    zycl.setKsl(psbaZycl.getSpyflKsl());
                    zycl.setKczh(psbaZycledit.getKczh());
                    psbaGtZyclList.add(zycl);
                }
                if (psbaZycl.getOtherDataJsl() != null || psbaZycl.getOtherDataKsl() != null) {
                    PsbaGtZycl zycl = new PsbaGtZycl();
                    zycl.setPsbabh(psbaZycledit.getPsbabh());
                    zycl.setKcdm(kcdm);
                    zycl.setZycllx(psbaZycl.getLxbm());
                    zycl.setTjdx(tjdx);
                    zycl.setKslx(psbaZycledit.getKslxDm());
                    zycl.setKspj(psbaZycledit.getKspjDm());
                    zycl.setZycllb(19007);
                    zycl.setJsl(psbaZycl.getOtherDataJsl());
                    zycl.setKsl(psbaZycl.getOtherDataKsl());
                    zycl.setKczh(psbaZycledit.getKczh());
                    psbaGtZyclList.add(zycl);
                }
            }

            //保存评审备案-质量
            List<Kszlzb> kszlzbs = psbaZycledit.getKszlzbs();
            if (kszlzbs != null){
                for (int i = 0; i < kszlzbs.size(); i++) {
                    Kszlzb kszlzb = kszlzbs.get(i);
                    PsbaGtZl zl = new PsbaGtZl();
                    zl.setPsbabh(psbaZycledit.getPsbabh());
                    zl.setKcdm(kcdm);
                    zl.setTjdx(Double.valueOf(tjdx));
//                zl.setTjdx(Double.valueOf(getTjdx(psbaZycledit)));
                    zl.setKslx(String.valueOf(psbaZycledit.getKslxDm()));
                    zl.setKspj(String.valueOf(psbaZycledit.getKspjDm()));
                    zl.setZfm(kszlzb.getZfm());
                    zl.setZfdw(kszlzb.getZfdw());
                    zl.setZfz(kszlzb.getZfz().intValue());
                    zl.setJzbs(psbaZycledit.getIfAverage());
                    zlList.add(zl);
                }
            }

        }
        iPsbaGtZyclService.saveBatch(psbaGtZyclList);
        iPsbaGtZlService.saveBatch(zlList);
    }

    /***
     * 根据矿产代码获取统计对象
     *
     * @param kcdm
     * @author Kevin
     * @since 2024/6/12 16:39
     */
    public Integer getTjdx(Integer kcdm) {
        //统计对象
        Integer tjdx = 0;
        try {
            QueryWrapper<Cb06Kc> queryWrapperKc = new QueryWrapper<>();
            queryWrapperKc.eq("kcdm", kcdm);
            List<Cb06Kc> cb06KcList = cb06KcMapper.selectList(queryWrapperKc);
            if (cb06KcList != null && cb06KcList.size() != 0) {
                Cb06Kc cb06Kc = cb06KcList.get(0);
                tjdx = cb06Kc.getTjdx();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return tjdx;
    }

    /***
     * 获取统计对象
     *
     * @author Kevin
     * @since 2024/6/12 16:39
     */
    public Integer getTjdx(PsbaZycledit psbaZycledit) {
        //统计对象
        Integer tjdx = 0;
        try {
            if (psbaZycledit.getJsldw() != null && !psbaZycledit.getJsldw().equals("")) {
                tjdx = Integer.parseInt(psbaZycledit.getJsldw());
            } else {
                tjdx = Integer.parseInt(psbaZycledit.getKsldw());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return tjdx;
    }

    /**
     * 非压覆详情查看-评审备案矿产资源储量
     */
    @Override
    public List<PsbakczyclVo> getDetailKcOut(String psbabh) {
        return iPsbaGtZyclService.getPsbakczyclVoList(psbabh);
    }

    /**
     * 非压覆详情查看-评审备案矿产资源储量-编辑列表
     */
    @Override
    public List<PsbaZycledit> getDetailKc(String psbabh) {
        List<PsbaZycledit> psbaZycleditList = new ArrayList<>();
        List<String> kslxpjList = psbaGtZyclMapper.getKslxpjList(psbabh);
        if (kslxpjList != null && kslxpjList.size() > 0) {
            for (String kslxpj : kslxpjList) {
                // 使用逗号作为分隔符进行分割
                String[] parts = kslxpj.split(",");
                // 获取三个部分
                Integer kslx = Integer.valueOf(parts[0]);  // 逗号前的部分
                Integer kspj = Integer.valueOf(parts[1]);  // 逗号后（如果有的话）的部分
                Integer kcdm = Integer.valueOf(parts[2]);  // 逗号后（如果有的话）的部分

                QueryWrapper<PsbaGtZycl> queryWrapper = new QueryWrapper<>();
                queryWrapper.eq("psbabh", psbabh);
                queryWrapper.eq("kslx", kslx);
                queryWrapper.eq("kspj", kspj);
                queryWrapper.eq("kcdm", kcdm);
                List<PsbaGtZycl> psbaGtZyclList = psbaGtZyclMapper.selectList(queryWrapper);

                List<String> zycllzList = psbaGtZyclMapper.getZycllzList(psbabh, kslx, kspj, kcdm);
                if (psbaGtZyclList != null && psbaGtZyclList.size() > 0) {
                    PsbaGtZycl psbaGtZyclget0 = psbaGtZyclList.get(0);
                    PsbaZycledit psbaZycledit = new PsbaZycledit();
                    psbaZycledit.setPsbabh(psbaGtZyclget0.getPsbabh());
//                    psbaZycledit.setKcbm(psbaGtZyclget0.getKcdm());
//                    psbaZycledit.setKslxDm(psbaGtZyclget0.getKslx());
//                    psbaZycledit.setKspjDm(psbaGtZyclget0.getKspj());
                    psbaZycledit.setKczh(psbaGtZyclget0.getKczh());

                   //质量列表
                    QueryWrapper<PsbaGtZl> zlQueryWrapper = new QueryWrapper<>();
                    zlQueryWrapper.eq("psbabh", psbabh);
                    zlQueryWrapper.eq("kspj",String.valueOf(kspj));
                    zlQueryWrapper.eq("kslx", String.valueOf(kslx));
                    zlQueryWrapper.eq("kcdm", kcdm);
                    List<PsbaGtZl> zlList = zlMapper.selectList(zlQueryWrapper);
                    if (zlList != null && zlList.size() > 0) {
                        //矿石主要成分及质量指标
                        List<Kszlzb> kszlzbs = new ArrayList<>();
                        for (PsbaGtZl zl : zlList) {
                            Kszlzb kszlzb = new Kszlzb();
                            kszlzb.setZfz(Double.valueOf(zl.getZfz()));
                            kszlzb.setZfdw(zl.getZfdw());
                            kszlzb.setZfm(zl.getZfm());
                            kszlzbs.add(kszlzb);
                        }
                        psbaZycledit.setKszlzbs(kszlzbs);
                    }


                    //矿石工业类型及品牌
                    String kslxpjmc = "";
                    QueryWrapper<Cb02Kslx> queryWrapperKslx = new QueryWrapper<>();
                    queryWrapperKslx.eq("kcdm", psbaGtZyclget0.getKcdm());
                    queryWrapperKslx.eq("kslx", psbaGtZyclget0.getKslx());
                    Cb02Kslx cb02Kslx = cb02KslxMapper.selectOne(queryWrapperKslx);
                    if (cb02Kslx != null) {
                        psbaZycledit.setKslx(cb02Kslx.getKslxmc());
                        psbaZycledit.setKslxDm(cb02Kslx.getKslx());
                    }

                    QueryWrapper<Cb03Kspj> queryWrapperKspj = new QueryWrapper<>();
                    queryWrapperKspj.eq("kcdm", psbaGtZyclget0.getKcdm());
                    queryWrapperKspj.eq("kspj", psbaGtZyclget0.getKspj());
                    Cb03Kspj cb03Kspj = cb03KspjMapper.selectOne(queryWrapperKspj);
                    if (cb03Kspj != null) {
                        psbaZycledit.setKspj(cb03Kspj.getKspjmc());
                        psbaZycledit.setKspjDm(cb03Kspj.getKspj());
                    }
                    //矿产名称
                    String kcmc = "";
                    //统计对象
                    String tjdx = "";
                    QueryWrapper<Cb06Kc> queryWrapperKc = new QueryWrapper<>();
                    queryWrapperKc.eq("kcdm", psbaGtZyclget0.getKcdm());
                    List<Cb06Kc> cb06KcList = cb06KcMapper.selectList(queryWrapperKc);
                    if (cb06KcList != null && cb06KcList.size() != 0) {
                        Cb06Kc cb06Kc = cb06KcList.get(0);
                        kcmc = cb06Kc.getKcmc();
                        if (cb06Kc.getJsldw() != null && !cb06Kc.getJsldw().equals("")) {
                            tjdx = kcmc + " " + cb06Kc.getJsldw();
                        } else {
                            tjdx = kcmc + " " + cb06Kc.getKsldw();
                        }
                        psbaZycledit.setTjdx(tjdx);
                        psbaZycledit.setKcmc(kcmc);
                        if (cb06Kc.getJsldw()!=null&&!cb06Kc.getJsldw().equals("")){
                            psbaZycledit.setKcbm("3_"+cb06Kc.getKcdm()+"_"+cb06Kc.getTjdx());
                        }else{
                            psbaZycledit.setKcbm("2_"+cb06Kc.getKcdm()+"_"+cb06Kc.getTjdx());
                        }


                        List<PsbaZycl> psbaZycls = new ArrayList<>();

                        for (String lxmc : zycllzList) {
                            QueryWrapper<Cb13Zycllx> queryWrapperZycllx = new QueryWrapper<>();
                            queryWrapperZycllx.eq("dm", lxmc);
                            Cb13Zycllx cb13Zycllx = cb13ZycllxMapper.selectOne(queryWrapperZycllx);
                            PsbaZycl psbaZycl = new PsbaZycl();
                            //ToDo 涉及新老数据库，需要修改同步
                            if (cb13Zycllx != null){
                                psbaZycl.setLxmc(cb13Zycllx.getMc());
                                psbaZycl.setLxbm(lxmc);
                            }else{
                                psbaZycl.setLxbm(lxmc);
                                psbaZycl.setLxmc(lxmc);
                            }


                            //勘察增减（±） 金属量
                            Double kczjJsl = 0.0;
                            //重算增减（±）金属量
                            Double cszjJsl = 0.0;
                            //年末保有 金属量
                            Double nmbyJsl = 0.0;
                            //累计查明 金属量
                            Double ljcmJsl = 0.0;
                            //审批压覆量 金属量
                            Double spyflJsl = 0.0;
                            //其他 金属量
                            Double otherDataJsl = 0.0;


                            //勘察增减（±） 矿石量
                            Double kczjKsl = 0.0;
                            //重算增减（±）矿石量
                            Double cszjKsl = 0.0;
                            //年末保有 矿石量
                            Double nmbyKsl = 0.0;
                            //累计查明 矿石量
                            Double ljcmKsl = 0.0;
                            //审批压覆量 矿石量
                            Double spyflKsl = 0.0;
                            //其他 矿石量
                            Double otherDataKsl = 0.0;
                            for (PsbaGtZycl psbaGtZycl : psbaGtZyclList) {

                                if (psbaGtZycl.getZycllb() == 19001 && lxmc.equals(psbaGtZycl.getZycllx())) {
                                    if (psbaGtZycl.getJsl() != null) {
                                        nmbyJsl = psbaGtZycl.getJsl();
                                    }
                                    nmbyKsl = psbaGtZycl.getKsl();
                                }
                                if (psbaGtZycl.getZycllb() == 19002 && lxmc.equals(psbaGtZycl.getZycllx())) {
                                    if (psbaGtZycl.getJsl() != null) {
                                        ljcmJsl = psbaGtZycl.getJsl();
                                    }
                                    ljcmKsl = psbaGtZycl.getKsl();

                                }
                                if (psbaGtZycl.getZycllb() == 19006 && lxmc.equals(psbaGtZycl.getZycllx())) {
                                    if (psbaGtZycl.getJsl() != null) {
                                        kczjJsl = psbaGtZycl.getJsl();
                                    }
                                    kczjKsl = psbaGtZycl.getKsl();

                                }
                                if (psbaGtZycl.getZycllb() == 19008 && lxmc.equals(psbaGtZycl.getZycllx())) {
                                    if (psbaGtZycl.getJsl() != null) {
                                        cszjJsl = psbaGtZycl.getJsl();
                                    }
                                    cszjKsl = psbaGtZycl.getKsl();

                                }
                                if (psbaGtZycl.getZycllb() == 19009 && lxmc.equals(psbaGtZycl.getZycllx())) {
                                    if (psbaGtZycl.getJsl() != null) {
                                        spyflJsl = psbaGtZycl.getJsl();
                                    }
                                    spyflKsl = psbaGtZycl.getKsl();

                                }
                                if (psbaGtZycl.getZycllb() == 19007 && lxmc.equals(psbaGtZycl.getZycllx())) {
                                    if (psbaGtZycl.getJsl() != null) {
                                        otherDataJsl = psbaGtZycl.getJsl();
                                    }
                                    otherDataKsl = psbaGtZycl.getKsl();

                                }
                            }
                            psbaZycl.setLjcmJsl(ljcmJsl);
                            psbaZycl.setLjcmKsl(ljcmKsl);
                            psbaZycl.setNmbyJsl(nmbyJsl);
                            psbaZycl.setNmbyKsl(nmbyKsl);
                            //勘察增减
                            psbaZycl.setKczjJsl(kczjJsl);
                            psbaZycl.setKczjKsl(kczjKsl);

                            // 重算增减
                            psbaZycl.setCszjJsl(cszjJsl);
                            psbaZycl.setCszjKsl(cszjKsl);
                            //审批压覆量
                            psbaZycl.setSpyflJsl(spyflJsl);
                            psbaZycl.setSpyflKsl(spyflKsl);
                            //其他
                            psbaZycl.setOtherDataJsl(otherDataJsl);
                            psbaZycl.setOtherDataKsl(otherDataKsl);
                            psbaZycls.add(psbaZycl);
                        }
                        psbaZycledit.setReserveDatas(psbaZycls);
                        psbaZycleditList.add(psbaZycledit);


                    }
                }


            }


        }


//        //资源储量列表
//        QueryWrapper<PsbaGtZycl> queryWrapper = new QueryWrapper<>();
//        queryWrapper.eq("psbabh", psbabh);
//        List<PsbaGtZycl> zyclList = psbaGtZyclMapper.selectList(queryWrapper);
//


        return psbaZycleditList;
    }
}
